package com.enjoyor.health.HGPT.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.enjoyor.health.HGPT.core.entity.DialogContent;
import com.enjoyor.health.HGPT.core.entity.DialogRecord;
import com.enjoyor.health.HGPT.core.mapper.DialogContentMapper;
import com.enjoyor.health.HGPT.core.service.IDialogContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 对话-内容记录 服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-18
 */
@Service
public class DialogContentServiceImpl extends ServiceImpl<DialogContentMapper, DialogContent> implements IDialogContentService {

    @Override
    public List<DialogContent> getDialogContentById(String dialogId) {
        QueryWrapper<DialogContent> queryWrapper = Wrappers.query();
        queryWrapper.eq("dialog_id", dialogId);
        queryWrapper.orderByAsc("number");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public int updateDialogContent(String evaluation, String evaluationDetail, String comment, String dialogId, String number) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("evaluation", evaluation);
        map.put("evaluation_detail", evaluationDetail);
        map.put("comment", comment);
        map.put("dialog_id", dialogId);
        map.put("number", number);
        return baseMapper.updateDialogContent(map);
    }

    @Override
    public DialogContent getLatestDialogById(String dialogId) {
        QueryWrapper<DialogContent> queryWrapper = Wrappers.query();
        queryWrapper.eq("dialog_id", dialogId);
        queryWrapper.orderByDesc("time");
        queryWrapper.last("limit 1");
        return baseMapper.selectOne(queryWrapper);
    }
}
